//
//  SPMessageViewController.m
//  Sport
//
//  Created by Cass on 2017/11/25.
//  Copyright © 2017年 Cass. All rights reserved.
//

#import "SPMessageViewController.h"
#import "SPFriendsViewController.h"
#import "SPAddFriendsViewController.h"
#import "SPRecentMessageCell.h"
#import "SPRecentMessage.h"
#import "SPChatViewController.h"
#import "SPUsersListViewController.h"

@interface SPMessageViewController ()<UITableViewDataSource,UITableViewDelegate>
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (nonatomic, strong) SPRecentMessage *recentMsg;

@end

@implementation SPMessageViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.tableView.tableFooterView = [[UIView alloc]init];
    SPRecentMessage *recentMsg = [[SPRecentMessage alloc]init];
    recentMsg.headImage = @"ha";
    recentMsg.friendName = @"王大锤";
    recentMsg.message = @"今天天气不错";
    recentMsg.time = @"14:40";
    self.recentMsg = recentMsg;
    
    self.tableView.dataSource = self;
    self.tableView.delegate = self;
    [self _setupData];
}
- (void)_setupData{
    self.navigationItem.title = @"消息";
    self.navigationItem.leftBarButtonItem = [UIBarButtonItem itemWithImage:nil selectedImage:nil title:@"好友" target:self action:@selector(friends:)];
    self.navigationItem.rightBarButtonItem = [UIBarButtonItem itemWithImage:@"tab_icon_jia" selectedImage:@"tab_icon_jia" title:nil target:self action:@selector(addFriends:)];
    
    //    UIImage *image = [UIImage imageNamed:@"message_normal"];
    //    image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    //    self.tabBarItem.image = image;
    //    UIImage *selectedImage = [UIImage imageNamed:@"message_highlight"];
    //    selectedImage = [selectedImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    //    self.tabBarItem.selectedImage = selectedImage;
}
- (void)friends:(UIBarButtonItem *)barButtonItem{
//    SPFriendsViewController *friendsVC = [[UIStoryboard storyboardWithName:@"Message" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:NSStringFromClass([SPFriendsViewController class])];
//    friendsVC.title = @"好友";
//    [self.navigationController pushViewController:friendsVC animated:YES];
    SPUsersListViewController *usersList = [[UIStoryboard storyboardWithName:@"Message" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:NSStringFromClass([SPUsersListViewController class])];
    usersList.title = @"好友";
    [self.navigationController pushViewController:usersList animated:YES];
}
- (void)addFriends:(UIBarButtonItem *)barButtonItem{
    SPAddFriendsViewController *addVC = [[UIStoryboard storyboardWithName:@"Message" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:NSStringFromClass([SPAddFriendsViewController class])];
    addVC.title = @"添加好友";
    [self.navigationController pushViewController:addVC animated:YES];
}

#pragma mark - UITableViewDataSource -
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 3;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    SPRecentMessageCell *cell = [SPRecentMessageCell recentMessageCellWithTableView:tableView];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.recentmessage = _recentMsg;
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    SPChatViewController *chatVC = [[UIStoryboard storyboardWithName:@"Message" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:@"chat"];
    [self.navigationController pushViewController:chatVC animated:YES];
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 55.0f;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
}


@end
